//
//  lernfile.m
//  
//
//  Created by 杨云中 on 15/9/26.
//
//

#import <Foundation/Foundation.h>

NSLog(@"hello");
// 将消息的结果赋值给一个变量，并且输出
NSArray *foods = @[@"tacos",@"burgers"];
NSString *result = [foods description];
NsLog(@"%@",result);

//===========================
NSString *city = @"Ice World";
NSUInteger cityLength = [city length];

//NSLog(@"City has %@ characters", cityLength); 错误的写法 与NSUInteger有关
NSLog(@"City has %lu characters", cityLength);

//=============Operating on NSNumbers
NSNumber *higgiesAge = @6;
NSNumber *phoneLives = @3;

//NSNumber *product = higgiesAge * phoneLives;  这种写法错误？ 理由？？？
NSLog(@"Higgie is actually %@ years old.", product);

NSNumber *higgiesAge = @6;
NSNumber *phoneLives = @3;

NSUInteger higgiesAgeInt = [higgiesAge unsignedIntegerValue];
NSUInteger phoneLivesInt = [phoneLives unsignedIntegerValue];

NSUInteger higgiesRealAge = higgiesAgeInt * phoneLivesInt;
NSLog(@"%lu",higgiesRealAge);

//============Appending 2 strings
NSString *firstName = @"jonas";
NSString *lastName = @"yang";

//NSString *fullName = firstName + lastName;错误的写法
NSString *fullName = [firstName stringByAppendingString:lastName];
NSLog(@"%@", fullName);

//======================Nesting messages
NSString *firstName = @"jonas";
NSString *lastName = @"yang";

NSString *fullName = [[firstName stringByAppendingString:@" "] stringByAppendingString:lastName];

NSLog(@"%@", fullName);

//+++++====================Working with long message names

NSString *firstName = @"jonas";
NSString *lastName = @"yang";

NSString *fullName = [[firstName stringByAppendingString:@" "]
                      stringByAppendingString:lastName];

NSString *replaced = [fullName stringByReplacingOccurrencesOfString:firstName
                                                         withString:lastName];

NSLog(@"%@",replaced);


//==================================copy
NSString *firstName = @"jonas";
NSString *emptyString = [NSString string]; //an empty string object:

NSString *copy = [NSString stringWithString:firstName];

NSLog(@"%@ is a copy of %@", copy, firstName);


//Creating an NSString with alloc/init
//alloc 占内存  没有初始化 初始化init 之后才能使用
NSArray *emptyArray = [NSArray array];
NSDictionary *emptyDict = [NSDictionary dictionary];

SString *emptyString = [[NSString alloc] init];
NSArray *emptyArray = [[NSArray alloc] init];
NSDictionary *emptyDictionary = [[NSDictionary alloc] init];

NSString *copy = [[NSString alloc] initWithString:otherString];
NSString *copy = [[NSString alloc] initWithString:firstName];

//

NSString *firstName = @"jonas";
NSString *lastName = @"yang";

NSString *fullName = [NSString stringWithFormat:@"%@ %@",firstName ,lastName];

NSLog(@"%@", fullName);





